﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using Bookkeeping.Core.Persistence;
using Bookkeeping.Persistence.Repositories;

namespace Bookkeeping.Persistence.Repositories
{
    public class PersistenceContext : IPersistenceContext
    {
        ISession session;

        public ISession Session 
        {
            get
            {
                if (session == null)
                    session = SessionFactorySingleton.OpenSession();

                return session;
            }
            set
            {
                session = value;
            }
        }


        public void Dispose()
        {
            if (session != null)
            {
                session.Dispose();
                session = null;
            }
        }

        public ITagRepository Tags
        {
            get { return new TagRepository(Session); }
        }

        public IPostRepository Posts
        {
            get { return new PostRepository(Session); }
        }
    }
}
